<?php

/**
 * Description of Api
 *
 * @author genghongfei
 */
class ApiController extends G_Controller {
    protected $_domain;
    public function __construct($App) {
        parent::__construct($App);
        $this->_domain = preg_replace("/.*\.(\S+\.\S+)$/", "$1", $_SERVER["HTTP_HOST"]);
    }
    public function login(){
        $name = $this->_get('name');
        $pass = $this->_get('pass');
        $func = $this->_get('callback');
        if($name AND $pass){
            $usersModel = new UsersModel;
            $userinfo = $usersModel->getUserByName($name);
            if($userinfo){
                if($userinfo['upass'] = md5($userinfo['key'].$pass)){//登录成功
                    //$this->_cookie($, $v, $time, '/', $this->_domain);
                    echo sprintf("%s(%s)",$func,  json_encode($userinfo));
                    die();
                }
            }
        }
    }
    public function test(){
        phpinfo();
    }
    public function reg(){
        $usersModel = new UsersModel;
        var_dump($usersModel->reg("feifei".rand(1,100), '123456'));
    }
    public function code(){}
    public function changepwd(){}
    public function resetpwd(){}
    public function setface(){}
    public function bindmobile(){}
    public function bindemail(){}
    public function setprofile(){}
}
